package com.three.crm.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.three.crm.R;
import com.three.crm.base.BaseFragment;
import com.three.crm.constant.AppConstant;
import com.three.crm.page.common.CallLogActivity;
import com.three.crm.page.feedback.QualityListActivity;
import com.three.crm.page.goods.ArrivalListActivity;
import com.three.crm.page.goods.GoodsListActivity;
import com.three.crm.page.procure.OrderListActivity;
import com.three.crm.page.task.TaskListActivity;
import com.three.crm.page.visit.VisitListActivity;
import com.three.crm.util.AppManager;
import com.three.crm.util.XpopupUtil;

/**
 * 工作台
 * created by lqd on 2024-01-04.
 */
public class WorkFragment extends BaseFragment {

    public WorkFragment() {}

    public static WorkFragment newInstance(int index, String title) {
        WorkFragment fragment = new WorkFragment();
        Bundle args = new Bundle();
        args.putInt(AppConstant.INDEX, index);
        args.putString(AppConstant.KEY_TITLE, title);
        fragment.setArguments(args);
        return fragment;
    }

    private TextView tvTitle;

    @Override
    protected void initArguments(Bundle bundle) {}

    @Override
    protected int bindLayout() {
        return R.layout.fragment_work;
    }

    @Override
    protected void initViews(View view, Bundle savedInstanceState) {
        tvTitle = $(R.id.tv_title);
        tvTitle.setText(R.string.work);
        $(R.id.iv_left).setVisibility(View.GONE);
    }

    @Override
    public void initListener() {
        $(R.id.ll_visit).setOnClickListener(this);
        $(R.id.ll_plan).setOnClickListener(this);
        $(R.id.ll_record).setOnClickListener(this);
        $(R.id.ll_buy).setOnClickListener(this);
        $(R.id.ll_order).setOnClickListener(this);
        $(R.id.ll_feedback).setOnClickListener(this);
        $(R.id.ll_arrive).setOnClickListener(this);
    }

    @Override
    public void widgetClick(View v) {
        int userType = AppManager.getLevel();
        switch (v.getId()){
            case R.id.ll_visit://拜访
                if (userType == 1 || userType == 3) {
                    startActivity(VisitListActivity.class);
                } else {
                    XpopupUtil.showTips(getActivity(), getString(R.string.You_currently_do_not_have_permission_to_access));
                }
                break;
            case R.id.ll_plan://任务
                if (userType == 1 || userType == 3) {
                    startActivity(TaskListActivity.class);
                } else {
                    XpopupUtil.showTips(getActivity(), getString(R.string.You_currently_do_not_have_permission_to_access));
                }
                break;
            case R.id.ll_record://货量上传
                if (userType == 1 || userType == 3) {
                    startActivity(GoodsListActivity.class);
                } else {
                    XpopupUtil.showTips(getActivity(), getString(R.string.You_currently_do_not_have_permission_to_access));
                }
                break;
            case R.id.ll_buy://采购下单
                startActivity(OrderListActivity.class);
//                if (userType == 1 || userType == 3) {
//
//                } else {
//                    XpopupUtil.showTips(getActivity(), getString(R.string.You_currently_do_not_have_permission_to_access));
//                }
                break;
            case R.id.ll_order:
                startActivity(CallLogActivity.class);
                break;
            case R.id.ll_feedback:
                startActivity(QualityListActivity.class);
                break;
            case R.id.ll_arrive:
                startActivity(ArrivalListActivity.class);
                break;
        }
    }

    @Override
    protected void initData(Context context) {}
}